//
//  JyInCollectionViewCell.m
//  WhereToTravel
//
//  Created by dlios on 15/10/15.
//  Copyright © 2015年 zhoushengmin. All rights reserved.
//

#import "JyInCollectionViewCell.h"

#define W self.contentView.frame.size.width
#define H self.contentView.frame.size.height

@implementation JyInCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night) name:@"night" object:nil];
    }
    return self;
}

- (void)createView {
    self.bgView = [[UIView alloc] init];
    self.bgView.backgroundColor = [UIColor colorWithRed:1.000 green:0.949 blue:0.785 alpha:1.000];
    [self.contentView addSubview:self.bgView];
    
    self.upImageView = [[UIImageView alloc] init];
    [self.bgView addSubview:self.upImageView];
    
    self.mistLabel = [[UILabel alloc] init];
    [self.bgView addSubview:self.mistLabel];
    self.mistLabel.numberOfLines = 0;
    self.mistLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    self.mistLabel.backgroundColor = [UIColor clearColor];
    
    self.downLeftLabel = [[UILabel alloc] init];
    [self.bgView addSubview:self.downLeftLabel];
    self.downLeftLabel.font = [UIFont systemFontOfSize:10];
    self.downLeftLabel.backgroundColor = [UIColor clearColor];

    self.downRightLabel = [[UILabel alloc] init];
    [self.bgView addSubview:self.downRightLabel];
    self.downRightLabel.font = [UIFont systemFontOfSize:10];
    self.downRightLabel.backgroundColor = [UIColor clearColor];
    self.downRightLabel.textAlignment = NSTextAlignmentRight;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.bgView.frame = CGRectMake(W * 0.05, 0, W * 0.9, H);
    self.upImageView.frame = CGRectMake(W * 0.05, 0, W * 0.8, H * 0.56);
    self.mistLabel.frame = CGRectMake(W * 0.05, H * 0.57, W * 0.8, H * 0.22);
    self.downLeftLabel.frame = CGRectMake(W * 0.05, H * 0.8, W * 0.4, H * 0.2);
    self.downRightLabel.frame = CGRectMake(W * 0.45, H * 0.8, W * 0.3, H * 0.2);
}

- (void)night {
    if ([SingletonNight shareSingletonNight].isSelete == YES) {
        self.bgView.backgroundColor = [UIColor blackColor];
        self.mistLabel.textColor = [UIColor whiteColor];
        self.downLeftLabel.textColor = [UIColor whiteColor];
        self.downRightLabel.textColor = [UIColor whiteColor];
    }
    else {
        self.bgView.backgroundColor = [UIColor colorWithRed:1.000 green:0.949 blue:0.785 alpha:1.000];
        self.mistLabel.textColor = [UIColor blackColor];
        self.downLeftLabel.textColor = [UIColor blackColor];
        self.downRightLabel.textColor = [UIColor blackColor];
    }
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
}



@end
